package com.spark.mooc.ch2_scala.part02_objectOrientedProgramming

/**
 * @description:
 * @time: 2020/11/24 19:19
 * @author: lhy
 */
/**
 * case类：经过优化的，用于模式匹配
 * 1.scala会自动的重载许多实用的方法：如，toString、equals、hashcode
 * 2.scala会为每一个case类生成一个对应的伴生对象
 */

case class Pig(name:String,age:Int)

object TestCase {
    def main(args: Array[String]): Unit = {
        val tom = Pig("Tom",21)
        val jock = Pig("Jack",23)
        val faceBook = Pig("FaceBook",30)
        for (pig <- List(tom,jock,faceBook)){
            pig match {
                case Pig("Tom",21) => println("hello tom!")
                case Pig(name,age) => println("Name:"+name+"\tAge:"+age)
            }
        }
    }
}
